import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1628951777208_2157';
  config.serverTimeout = 10000;

  // 跨域相关配置
  config.security = {
    domainWhiteList: [ '*' ], // 允许哪个地址跨域请求
    csrf: {
      enable: false,
    },
  };
  // 跨域相关配置
  config.cors = {
    // origin: '*', // 允许哪个地址跨域请求
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH', // 允许哪些方法跨域请求
    credentials: true, // 允许前端携带cookie
  };
  // add your egg config in here 中间件
  config.middleware = [ 'auth' ];
  // 配置 auth 中间件的配置
  config.auth = {
    // 需要进行权限控制的地址
    authUrls: [
      '/users',
    ],
  };

  // 文件上传相关配置
  config.multipart = {
    mode: 'file',
    fileSize: '10mb',
    // 添加接收Excel表
    fileExtensions: [
      '.xlsx',
    ],
  };

  // 第三方登录Github配置
  config.passportGithub = {
    key: '73cee7164770ff0b4225',
    secret: 'b6009aebbe46b8f7833a4c94b9f9cdaebead91bc',
  };

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
